/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2025-04-15
 * Time: 17:20
 */
//饿汉模式
class Singleton {
    //在类加载的时候就触发
    private static Singleton instance = new Singleton();

    public static Singleton getInstance() {
        return instance;
    }
    //单例模式的点睛之笔
    private Singleton() {

    }
}
public class Demo36 {
    public static void main(String[] args) {
        Singleton t1 = Singleton.getInstance();
        Singleton t2 = Singleton.getInstance();
        System.out.println(t1 == t2);//获取到的是同一个对象
        //Singleton t3 = new Singleton();
    }
}
